#include "TreeStruct.h"

CTreeStruct* _stdcall TreeStruct_Create()
{
	CTreeStruct* pNode = new CTreeStruct;
	pNode->m_pParent = NULL;
	pNode->m_pRoot = pNode;
	return pNode;
}

void _stdcall TreeStruct_Destory( CTreeStruct* pNode )
{
	delete pNode;
}

void _stdcall TreeStruct_SetText( CTreeStruct* pNode,LPCTreeStructString lpText )
{
	pNode->m_string = lpText;
}

LPCTreeStructString _stdcall TreeStruct_GetText( CTreeStruct* pNode )
{
	return pNode->m_string.c_str();
}

size_t _stdcall TreeStruct_GetChildCount( CTreeStruct* pNode )
{
	return pNode->m_Childrens.size();
}

CTreeStruct* _stdcall TreeStruct_GetChild( CTreeStruct* pNode,int nIndex )
{
	return pNode->m_Childrens[nIndex];
}

CTreeStruct* _stdcall TreeStruct_InsertChild( CTreeStruct* pNode,int nIndex,LPCTreeStructString lpText)
{
	CTreeStruct* lpNode = pNode->InsertChild(nIndex);
	lpNode->m_string = lpText;
	return lpNode;
}

CTreeStruct* _stdcall TreeStruct_AddChild( CTreeStruct* pNode )
{
	return pNode->AddChild();
}

CTreeStruct* _stdcall TreeStruct_AddChildText( CTreeStruct* pNode,LPCTreeStructString lpText )
{
	CTreeStruct* lpNode = TreeStruct_AddChild(pNode);
	lpNode->m_string = lpText;
	return lpNode;
}

bool _stdcall TreeStruct_DeleteChild( CTreeStruct* pNode,int nIndex )
{
	delete pNode->m_Childrens[nIndex];
	pNode->m_Childrens.erase(pNode->m_Childrens.begin()+nIndex);
	return true;
}

CTreeStruct* _stdcall TreeStruct_GetRoot( CTreeStruct* pNode )
{
	return pNode->m_pRoot;
}

CTreeStruct* _stdcall TreeStruct_GetParent( CTreeStruct* pNode )
{
	return pNode->m_pParent;
}

std::string _stdcall TreeStruct_ToBin( CTreeStruct* pNode )
{
	return pNode->toBin();
}

void _stdcall TreeStruct_FromBin( CTreeStruct* pNode,void* pData,int nDataLen)
{
	pNode->fromBin(pData,nDataLen);
}

void _stdcall TreeStruct_SetUserData1( CTreeStruct* pNode,void* pData)
{
	pNode->m_pUserData1 = pData;
}

void _stdcall TreeStruct_SetUserData2( CTreeStruct* pNode,void* pData)
{
	pNode->m_pUserData2 = pData;
}

void* _stdcall TreeStruct_GetUserData1( CTreeStruct* pNode)
{
	return pNode->m_pUserData1;
}

void* _stdcall TreeStruct_GetUserData2( CTreeStruct* pNode)
{
	return pNode->m_pUserData2;
}